import type {
  GetSpuResData,
  AllTrademarks,
  ResSpuImgList,
  ResSpuAttr,
  ResSaleAttr,
  SpuData,
  resSkuInfo,
} from './type'
//SPU管理的接口
import request from '@/utils/request'
enum API {
  // 获取SPU数据
  getSPU_url = '/admin/product/',
  // 获取所有品牌数据
  alltrademark_url = '/admin/product/baseTrademark/getTrademarkList',
  // 获取当前spu品牌下全部售卖的商品图片
  spu_imagelist_url = '/admin/product/spuImageList/',
  // 获取当前spu下的全部销售属性
  spu_attr_url = '/admin/product/spuSaleAttrList/',
  // 获取全部销售属性
  sale_attr_url = '/admin/product/baseSaleAttrList',
  // 添加spu
  add_spu_url = '/admin/product/saveSpuInfo',
  // 修改spu
  update_spu_url = '/admin/product/updateSpuInfo',
  // 删除spu
  delete_spu_url = '/admin/product/deleteSpu/',

  // 通过spuid获取sku列表
  skulist_url = '/admin/product/findBySpuId/'
}

// 获取三级分类下的SPU数据
export const reqGetSPU = (page: number, limit: number, c3: string | number) =>
  request.get<any, GetSpuResData>(API.getSPU_url + `${page}/${limit}?category3Id=${c3}`)

// 获取所有品牌数据
export const reqAlltrademark = () =>
  request.get<any, AllTrademarks>(API.alltrademark_url)

// 获取spu的图片列表
export const reqSpuImage = (spuId: number) =>
  request.get<any, ResSpuImgList>(API.spu_imagelist_url + spuId)

// 获取spu的销售属性列表
export const reqSpuAttr = (spuId: number) =>
  request.get<any, ResSpuAttr>(API.spu_attr_url + spuId)

// 获取所有销售属性列表
export const reqSaleAttr = () =>
  request.get<any, ResSaleAttr>(API.sale_attr_url)

// 添加/修改spu
export const reqAddOrUpdateSpu = (data: SpuData) => {
  if (data.id) return request.post<any, any>(API.update_spu_url, data)
  return request.post<any, any>(API.add_spu_url, data)
}

// 删除spu
export const reqDeleteSpu = (id: number) => request.delete<any,any>(API.delete_spu_url+id)

// 获取对应spuid的sku列表
export const reqSkuListBySpuId = (id: number) => request.get<any,resSkuInfo>(API.skulist_url+id)